<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});




//需要使用access_token的数据
Route::group(['namespace'=>'V1','middleware' => ['api','passport.api.auth']],function (){

    Route::group(['namespace'=>'API'],function (){

        Route::group(['prefix' => 'v1'],function (){
            /***
             * 用户相关接口
             */
            Route::group(['prefix' => 'user'],function (){
                // 获取用户个人信息
                Route::get('/detail','UserInformationsController@userDetail');

                // 更新用户个人信息
                Route::post('/update','UserInformationsController@updateData');

                // 用户上传头像
                Route::post('/avatar','UserInformationsController@updateAvatar');

                Route::get('/me','UserInformationsController@getAuthenticatedUser');
            });

            /***
             * 校服相关接口
             */
            Route::group(['prefix' => 'clothes'],function (){
                //获取所有校服数据
                Route::get('','ApplyClothController@getClothes');
                // 选择尺码
                Route::post('/size','ApplyClothController@selectClothSizes');
            });

            /***
             * 住宿
             */
            Route::group(['prefix' => 'dorms'],function (){
                //宿舍申请
                Route::post('/apply','ApplyDormsController@applyDorm');

                //查看我的宿舍申请
                Route::get('/apply','ApplyDormsController@myApplyDorm');
            });

            /***
             * 军训延迟
             */
            Route::group(['prefix' => 'trainings'],function (){
                //军训延迟申请
                Route::post('/apply','ApplyTraitDelayController@applyTraitDelay');
                //查看我的军训延迟申请
                Route::get('/apply','ApplyTraitDelayController@myApplyTraitDelay');

            });

            /***
             * 专业（志愿）填报
             */
            Route::group(['prefix' => 'majors'],function (){
                //获取专业列表
                Route::get('/apply','ApplyMajorsController@getMajors');
                //申请专业（志愿）
                Route::post('/apply','ApplyMajorsController@applyMajor');
            });

            /***
             * 缴费
             */
            Route::group(['prefix' => 'pays'],function (){
                //获取缴费项
                Route::get('','ApplyPaysController@paysData');
            });

            /***
             * 微信支付相关
             */
            Route::group(['prefix' => 'wechat'],function (){
                // 支付，获取prepayid后，再次签名返回
                Route::post('/pay/order','WeChatPayController@unifiedOrder');
            });

            /***
             * 现场报到
             */
            Route::group(['prefix' => 'report'],function (){
                //获取现场报到流程
                Route::get('/processes','ReportProcessController@getProcesses');

                //获取流程详情
                Route::get('/oneProcessDetail','ReportProcessController@getProcessDetail');

                //获取所有流程
                Route::get('/allProcessDetail','ReportProcessController@getAllProcessDetail');

                //报到（扫描二维码后）
                Route::post('','ReportProcessController@userReport');
                
            });

            /***
             * 图片上传
             */
            Route::group(['prefix' => 'upload'],function (){
                Route::post('trainings/images', 'ImageUploadController@uploadTrainingsImage');
            });

        });
    });
});


//不需要使用access_token的数据
Route::group(['namespace'=>'V1','middleware' =>'api'],function (){

    Route::group(['namespace'=>'API'],function (){

        Route::group(['prefix' => 'v1'],function (){
            Route::group(['prefix' => 'user'],function (){
                /***
                 * App用户登录
                 */
                Route::post('/login','UserInformationsController@login');
            });

            /***
             * 微信相关接口
             */
            Route::group(['prefix' => 'wechat'],function (){
                // 获取用户个人信息
                Route::post('/login','WeChatController@wechatLogin');
                // 获取用户个人信息
                Route::get('/userInfo','WeChatController@getUserInfo');
                // 退出登录
                Route::get('/logout','WeChatController@wechatLogout');

                // 微信支付回调
                Route::post('/pay/notify','WeChatPayController@orderNotify');

                // 测试
                Route::get('/test','WeChatPayController@test');
            });

            /***
             * 迎新日程相关接口
             */
            Route::group(['prefix' => 'timetables'],function (){
                
                //获取日程接口
                Route::get('','TimetableController@getTimetables');
                
                //获取日程所属相关类别数据列表
                Route::get('/timetable_category','TimetableController@getTimetableCategory');
                
            });

            /***
             * 通知公告
             */
            Route::group(['prefix' => 'notices'],function (){
                /***
                 * 查询新闻所有栏目
                 */
                Route::get('/programs','NoticeDetailsController@getNoticesProgram');

                /***
                 * 根据栏目ID，获取当前栏目下的所有新闻
                 */
                Route::get('','NoticeDetailsController@getNoticesByProgramID');

                /***
                 * 根据新闻ID，获取新闻详情
                 */
                Route::get('/detail','NoticeDetailsController@getNoticeDetailByID');

            });



            /***
             *  致新生的信／学校概况
             */
            Route::group(['prefix' => 'notices'],function (){
                /***
                 * 查询新闻所有栏目
                 */
                Route::get('/message','NoticeDetailsController@getStudentMessage');

                /***
                 * 根据栏目ID，获取当前栏目下的所有新闻
                 */
                Route::get('/situation','NoticeDetailsController@getSchoolSituation');

            });

            // 名师风采
            Route::group(['prefix' => 'excellent'], function () {
                Route::group(['prefix' => 'teachers'], function () {
                    Route::get('', 'ExcellentTeachersController@teachersData');
                });
            });


            /***
             * 校区
             */
            Route::group(['prefix' => 'colleges'],function (){
                //获取校区
                Route::get('','CollegesController@collegesData');
            });

            /***
             * 滚动图片
             */
            Route::group(['prefix' => 'scroll'],function (){
                Route::get('/images', 'ScrollImagesController@getScrollImages');
            });
            
            
            /***
            * 权限->用户
            */
            Route::group(['prefix' => 'users'], function () {
               // 获取所有用户   包含教师和学生
               Route::get('', 'UsersController@index');

               //  编辑用户的角色
               Route::patch('{code}', 'UsersController@updateData');

               //删除用户角色
               Route::delete('', 'UsersController@deleteData');
            });

            /***
            * 权限->角色
            */
            Route::group(['prefix' => 'roles'], function () {
               //获取所有的角色
               Route::get('', 'RolesController@index');

               //获取角色详情
               Route::get('{name}', 'RolesController@show');

               //添加角色
               Route::post('', 'RolesController@addData');

               //编辑角色
               Route::patch('{name}', 'RolesController@updateData');

               //删除角色
               Route::delete('', 'RolesController@deleteData');
            });

            /**
            * 权限->权限
            */
            Route::group(['prefix' => 'permissions'], function () {

               //获取所有的权限
               Route::get('', 'PermissionsController@index');

            });
            
            /**
             * 小程序新生信息
             */
            Route::group(['prefix' => 'new_student'],function (){
                
                // 根据userID获取新生个人信息
                Route::get('/get_new_student_information', 'NewStudentsController@getNewStudentInformation');
                
                // 添加/更新 新生基本信息
                Route::post('/edit_new_student_information', 'NewStudentsController@editNewStudentInformation');
                
                // 获取新生列表(暂时用不到)
                Route::get('/get_new_student_list', 'NewStudentsController@getNewStudentList');
                
                // 根据省,市获取学校接口
                Route::get('/select_city_school', 'NewStudentsController@selectCitySchool');
                
                // 专业选择
                Route::get('/select_professional', 'NewStudentsController@selectProfessional');
                
            });
            
            /**
             * 小程序注册
             */
            Route::group(['prefix' => 'small_program'],function (){
                
                //小程序注册
                Route::post('/register', 'SmallProgramController@register');
                
                //小程序扫码 身份确认
                Route::get('/student_detail', 'SmallProgramController@studentDetail');
                
            });
            
        });
    });
});
